<template>
  <div class="banner-page">
    <div class="container">
      <div class="header-title">
        <img src="https://static.360buyimg.com/mtd/pc/fresh_v3/1.0.0/home/images/fresh_mod_head_bg.png" alt="">
        <p>{{ bannerData.name }}</p>
      </div>
      <div class="banner-box">
        <div class="wrapper">
          <div class="banner-top-box">
            <div class="banner-img-left"
                 :style="`background-image: url(${bannerData.imageBgUrl})`">
              <h4>{{ bannerData.subTitle }}</h4>
              <p>{{ bannerData.subBrief }}</p>
              <div class="product-list" >
                <a :href="`/detail/` + item.id" v-for="(item, index) in getSmallProduct()" :key="index">{{ item.name }}</a>
<!--                <a href="">芒果</a>
                <a href="">哈密瓜</a>
                <a href="">葡萄</a>
                <a href="">苹果</a>
                <a href="">水蜜桃</a>-->
              </div>
            </div>
            <div class="banner-img">
              <a :href="`/detail/` + bannerData.imageMainId"><img class="img-left" v-lazy="bannerData.imageMainUrl" alt=""></a>
              <a :href="`/detail/` + bannerData.imageRightId"><img class="img-right" v-lazy="bannerData.imageRightUrl" alt=""></a>
            </div>
          </div>
          <div class="banner-goods">
            <div class="goods-item" v-for="(item, index) in getGoodsMain()" :key="index">
              <a :href="`/detail/` + item.id" target="_blank">
                <img
                    v-lazy="item.mainImage"
                    alt="">
                <p>{{ item.subtitle }}</p>
              </a>
            </div>
            <!--            <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd2.alicdn.com/imgextra/i2/2370006956/O1CN01E3bdcX21FtsEeuBi3_!!2370006956.jpg_400x400.jpg"
                                alt="">
                            <p>绿心猕猴桃新鲜应季水果整箱包邮孕妇绿大果当季奇异果弥猴桃</p>
                          </a>
                        </div>
                        <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd2.alicdn.com/imgextra/i2/2370006956/O1CN01E3bdcX21FtsEeuBi3_!!2370006956.jpg_400x400.jpg"
                                alt="">
                            <p>绿心猕猴桃新鲜应季水果整箱包邮孕妇绿大果当季奇异果弥猴桃</p>
                          </a>
                        </div>
                        <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd2.alicdn.com/imgextra/i2/2370006956/O1CN01E3bdcX21FtsEeuBi3_!!2370006956.jpg_400x400.jpg"
                                alt="">
                            <p>绿心猕猴桃新鲜应季水果整箱包邮孕妇绿大果当季奇异果弥猴桃</p>
                          </a>
                        </div>-->
          </div>
          <div class="banner-goods-bottom">
            <div class="goods-item" v-for="(item, index) in getGoodsFooter()" :key="index">
              <a :href="`/detail/` + item.id" target="_blank">
                <img
                    v-lazy="item.mainImage"
                    alt="">
              </a>
            </div>
            <!--            <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd4.alicdn.com/imgextra/i2/771829867/O1CN01vjJkry2Ml8ZpBSdcb_!!771829867.jpg_400x400.jpg"
                                alt="">
                          </a>
                        </div>
                        <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd4.alicdn.com/imgextra/i2/771829867/O1CN01vjJkry2Ml8ZpBSdcb_!!771829867.jpg_400x400.jpg"
                                alt="">
                          </a>
                        </div>
                        <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd4.alicdn.com/imgextra/i2/771829867/O1CN01vjJkry2Ml8ZpBSdcb_!!771829867.jpg_400x400.jpg"
                                alt="">
                          </a>
                        </div>
                        <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd4.alicdn.com/imgextra/i2/771829867/O1CN01vjJkry2Ml8ZpBSdcb_!!771829867.jpg_400x400.jpg"
                                alt="">
                          </a>
                        </div>
                        <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd4.alicdn.com/imgextra/i2/771829867/O1CN01vjJkry2Ml8ZpBSdcb_!!771829867.jpg_400x400.jpg"
                                alt="">
                          </a>
                        </div>
                        <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd4.alicdn.com/imgextra/i2/771829867/O1CN01vjJkry2Ml8ZpBSdcb_!!771829867.jpg_400x400.jpg"
                                alt="">
                          </a>
                        </div>
                        <div class="goods-item">
                          <a href="">
                            <img
                                src="https://gd4.alicdn.com/imgextra/i2/771829867/O1CN01vjJkry2Ml8ZpBSdcb_!!771829867.jpg_400x400.jpg"
                                alt="">
                          </a>
                        </div>-->
          </div>
        </div>
      </div>
      <div class="banner-footer">
        <ul>
          <li><span class="icon-setting"></span>食品安全</li>
          <li><span class="icon-7day"></span>鲜活天然</li>
          <li><span class="icon-15day"></span>产地直采</li>
          <li><span class="icon-post"></span>无忧售后</li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "bannerPage",
  data() {
    return {
      bannerData: {},
      productList: [],
      goodsMainList: [], //主要商品
      goodsFooterList: [], //次要商品
      smallProduct: [], //小标签商品链接
    }
  },
  mounted() {
    this.getBanner()
    this.getProductList()
  },
  methods: {
    getCategoryId() {
      return this.$route.params.categoryId
    },
    getBanner() {
      console.log(this.getCategoryId())
      this.request.get('/banner/' + this.getCategoryId() + '').then((res) => {
        this.bannerData = res
      })
    },
    getProductList() {
      this.request.get('/products/list').then((res) => {
        this.productList = res
      })
    },
    getGoodsMain() {
      const product = this.productList.filter(item =>
          item.categoryId == this.getCategoryId()
      )
      return product.slice(0, 4)
    },
    getGoodsFooter() {
      const product = this.productList.filter(item =>
          item.categoryId == this.getCategoryId()
      )
      return product.slice(4, 12)
    },
    getSmallProduct() {
      const product = this.productList.filter(item =>
          item.categoryId == this.getCategoryId()
      )
      return product.slice(6, 12)
    }
  }
}
</script>

<style scoped lang="scss">
@import "../assets/scss/config.scss";
@import "../assets/scss/base.scss";
@import "../assets/scss/mixin.scss";

.banner-page {
  background-color: $colorJ;

  .header-title {
    height: 100px;
    line-height: 100px;
    position: relative;
    text-align: center;
    letter-spacing: 10px;

    p {
      font-size: 28px;
      position: absolute;
      top: -10px;
      left: 50%;
      transform: translateX(-50%);
    }
  }

  .banner-box {
    margin-bottom: 30px;

    .wrapper {
      background-color: $colorG;

      .banner-top-box {
        height: 300px;

        .banner-img-left {
          padding: 0 20px;
          float: left;
          width: 160px;
          min-width: 140px;
          height: 300px;
          position: relative;

          h4 {
            color: $colorG;
            font-size: 26px;
            height: 39px;
            margin-bottom: 10px;
            padding-top: 20px;
          }

          p {
            color: $colorG;
            font-size: 16px;
            margin-bottom: 25px;
            height: 24px;
            white-space: nowrap;
            padding-bottom: 10px;

            &:after {
              content: '';
              position: absolute;
              top: 100px;
              left: 20px;
              width: 70px;
              height: 5px;
              background-color: $colorG;
            }
          }

          .product-list {
            height: 117px;

            a {
              float: left;
              margin: 0 9px 14px 0;
              padding: 0 13px;
              max-width: 132px;
              height: 28px;
              line-height: 28px;
              text-align: center;
              font-size: 14px;
              color: $colorG;
              border: 1px solid #ddd;
              background-color: rgba(255, 255, 255, 0.15);
              border-radius: 15px;

              &:hover {
                background-color: rgba(204, 204, 204, 0.45);
              }
            }
          }
        }

        .banner-img {
          .img-left {
            width: 726px;
            height: 300px;
            //object-fit: cover;
          }

          .img-right {
            width: 300px;
            height: 300px;
          }
        }
      }

      .banner-goods {
        height: 280px;
        @include flex();

        .goods-item {
          padding: 0 20px;
          text-align: center;

          a {
            img {
              transition: all .25s ease-in-out;
              width: 150px;
              height: 150px;
              margin-bottom: 20px;
            }

            p {
              color: $colorI;
              font-size: 14px;
            }
            &:hover {
              img {
                transform: translate3d(0, -3px, 0);
              }
              p {
                color: $colorA;
              }
            }
          }
        }
      }

      .banner-goods-bottom {
        height: 80px;
        border-top: 1px solid $colorF;
        box-sizing: border-box;

        .goods-item {
          text-align: center;
          float: left;
          width: 132px;
          padding: 0 10px;
          border-right: 1px solid $colorF;
          height: 80px;
          line-height: 80px;

          &:last-child {
            border: none;
          }

          a {
            &:hover {
              img {
                transform: translate3d(0, -3px, 0);
              }
            }
            img {
              transition: all .25s ease-in-out;
              margin-top: 15px;
              width: 60px;
              height: 50px;
            }

          }
        }
      }
    }
  }

  .banner-footer {
    padding: 33px 0;
    color: $colorC;
    font-size: 16px;
    //background-color: $colorG;
    li {
      display: inline-block;
      width: 24.9%;
      text-align: center;
      border-right: 1px solid $colorE;
      letter-spacing: 10px;

      &:last-child {
        border-right: none;
      }

      span {
        display: inline-block;
        width: 20px;
        height: 20px;
        vertical-align: middle;
        margin-right: 8px;
      }

      .icon-setting {
        @include bgImg(20px, 20px, '../../public/imgs/zhiliangbaozheng.png')
      }

      .icon-7day {
        @include bgImg(20px, 20px, '../../public/imgs/shuye.png')
      }

      .icon-15day {
        @include bgImg(20px, 20px, '../../public/imgs/gouwuche.png')
      }

      .icon-post {
        @include bgImg(20px, 20px, '../../public/imgs/shouhou.png')
      }
    }
  }
}
</style>